﻿namespace ParkingLot2
{
    public class ParkingLot
    {
        private readonly int _marxPackingNumber;
        private int _currentCarNumber { get; set; }=0;

        public ParkingLot(int marxPackingNumber,int currentCarNumber=0)
        {
            if (marxPackingNumber <= 0)
                throw new ArgumentException("停车场容量初始化错误");
            _marxPackingNumber = marxPackingNumber;
            if (currentCarNumber < 0)
                throw new ArgumentException("当前停车数量错误");
            _currentCarNumber = currentCarNumber;
            if (currentCarNumber > marxPackingNumber)
                throw new ArgumentException("当前停车数量大于停车场容量");
        }
        public bool IsParkingLotFull()
        {
            if (GetEmptyNumber()==0)
                return true;
            return false;
        }
        public int GetEmptyNumber()
        {
            return _marxPackingNumber - _currentCarNumber;
        }

        public bool Parking()
        {
            if (_currentCarNumber > _marxPackingNumber)
                throw new Exception("超出停车数量");
            _currentCarNumber++;
            Console.WriteLine("车停好了");
            return true;
        }

        public bool Picking()
        {
            if (_currentCarNumber <=0)
                throw new Exception("没有车");
            _currentCarNumber--;
            Console.WriteLine("车取走了");
            return true;
        }
    }
}
